package org.lex.game.sudoku.view;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

public class HistoryTableCellRender extends DefaultTableCellRenderer {
	private static final long serialVersionUID = -7959632922467280440L;

	private Font normalFont = null;
	private Font markerFont = null;

	private Color markerBg = null;

	public HistoryTableCellRender() {
		this.normalFont = this.getFont();
		this.markerFont = normalFont.deriveFont(Font.BOLD);
		this.markerBg = Color.YELLOW;
		this.setHorizontalAlignment(SwingConstants.CENTER);
		this.setVerticalAlignment(SwingConstants.CENTER);
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {
		super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		HistoryTableModel model = (HistoryTableModel) table.getModel();
		if (model.isMarked(row)) {
			this.setFont(this.markerFont);
			if (false == isSelected) {
				this.setBackground(this.markerBg);
			} else {
				this.setBackground(table.getSelectionBackground());
			}
		} else {
			this.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
		}
		return this;
	}
}
